package team.gzjmzy.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.gzjmzy.system.mapper.TBookMapper;
import team.gzjmzy.system.domain.entity.TBook;
import team.gzjmzy.system.service.ITBookService;

/**
 * 图书馆里Service业务层处理
 * 
 * @author gzjmzy
 * @date 2021-08-05
 */
@Service
public class TBookServiceImpl extends ServiceImpl<TBookMapper, TBook> implements ITBookService {

    @Override
    public List<TBook> queryList(TBook tBook) {
        LambdaQueryWrapper<TBook> lqw = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(tBook.getTitle())){
            lqw.eq(TBook::getTitle ,tBook.getTitle());
        }
        if (tBook.getCost() != null){
            lqw.eq(TBook::getCost ,tBook.getCost());
        }
        if (tBook.getDelTime() != null){
            lqw.eq(TBook::getDelTime ,tBook.getDelTime());
        }
        if (tBook.getType() != null){
            lqw.eq(TBook::getType ,tBook.getType());
        }
        return this.list(lqw);
    }

    /**
        * 查询通过Id
        * @param id
        */
    @Override
    public TBook queryById(String id) {
        return this.getById(id);
    }

    /**
     * 新增
     */
    @Override
    public boolean add(TBook tBook) {
        return this.save(tBook);
    }

    /**
     * 修改
     */
    @Override
    public boolean edit(TBook tBook) {
        return this.updateById(tBook);
    }

                                        
    /**
     * 删除
     */
    @Override
    public boolean delByIds(List<String> idList) {
        return this.removeByIds(idList);
    }

    @Override
    public String postStatus(TBook tBook) {
        TBook byId = this.getById(tBook.getId());
        byId.setStatus(tBook.getStatus());
        this.updateById(byId);
        return "1";
    }

}
